package com.chy.cms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chy.cms.pojo.CrmBanner;
import com.chy.cms.service.CrmBannerService;
import com.chy.commonutils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台banner管理接口
 * </p>
 *
 * @author chy
 * @since 2020-10-29
 */
@RestController
@RequestMapping("/educms/banner/admin")
@CrossOrigin
public class BannerAdminController {

    @Autowired
    private CrmBannerService bannerService;

    @ApiOperation(value = "分页查询banner")
    @GetMapping("pageBanner/{current}/{size}")
    public Result pageBanner(@PathVariable long current,@PathVariable long size) {
        Page<CrmBanner> page = new Page<>(current,size);
        bannerService.page(page,null);
        return Result.ok()
                .data("items",page.getRecords())
                .data("total",page.getTotal());
    }

    @ApiOperation(value = "添加banner")
    @PostMapping("addBanner")
    public Result addBanner(@RequestBody CrmBanner crmBanner) {
        bannerService.save(crmBanner);
        return Result.ok();
    }

    @ApiOperation(value = "获取Banner")
    @GetMapping("getBanner/{id}")
    public Result getBanner(@PathVariable String id) {
        CrmBanner banner = bannerService.getById(id);
        return Result.ok().data("item", banner);
    }

    @ApiOperation(value = "修改Banner")
    @PutMapping("updateBanner")
    public Result updateBanner(@RequestBody CrmBanner banner) {
        bannerService.updateById(banner);
        return Result.ok();
    }
    @ApiOperation(value = "删除Banner")
    @DeleteMapping("removeBanner/{id}")
    public Result removeBanner(@PathVariable String id) {
        bannerService.removeById(id);
        return Result.ok();
    }
}

